<template>
    <view>
        <view v-if="detail != null" class="bigpage">
			<!-- #ifdef APP-PLUS -->
			<!-- 右侧icon -->
			<view class="top-share-right-icon">
			    <uni-icons type="redo" size="20" color="#333" class="icon round cp" @tap="popup_share_event"></uni-icons>
			</view>
			<!-- #endif -->
			<!--宣传语-->
			<view class="kan_box">
			    <view class="kan_body">
			        <view class="user-info">
			            <image class="img1" :src="detail.team_head_user.avatar" mode="aspectFit" />
			            <view class="user-name">{{ detail.teamname }}</view>
			        </view>
					<!--玩家自己的拼团状态成功与否，要综合判断-->
					<block v-if="detail.items[0].wanfa == 2">
						<block v-if="detail.buchang_get == 0">
							<block v-if="detail.is_team == 2">
								<view class="timebox">{{lang_info.PINSTATUS2}}</view>
							</block>
							<block v-else-if="detail.is_team == 1">
								<view class="timebox">{{lang_info.PINSTATUS3}}</view>
							</block>
							<block v-else>
								<block v-if="detail.items[0].is_over">
									<view class="timebox">{{lang_info.PINSTATUS4}}</view>
								</block>
								<block v-else>
									<view class="timebox">
										<component-countdown :propHour="detail.items[0].time.hours" :propMinute="detail.items[0].time.minutes" :propSecond="detail.items[0].time.seconds" :propTextTips="lang_info.detail_cutdown_tips_1" :propTextTipsEnd="lang_info.detail_cutdown_tips_2"></component-countdown>
									</view>
								</block>
							</block>
						</block>
						<block v-else>
							<view class="timebox">{{lang_info.PINSTATUS3}}</view>
						</block>
					</block>
					<block v-else>
						<view v-if="detail.is_team == 0" class="timebox">
							<component-countdown :propHour="detail.items[0].time.hours" :propMinute="detail.items[0].time.minutes" :propSecond="detail.items[0].time.seconds" :propTextTips="lang_info.detail_cutdown_tips_1" :propTextTipsEnd="lang_info.detail_cutdown_tips_2"></component-countdown>
						</view>
						<view v-else-if="detail.is_team == 1" class="timebox">{{lang_info.PINSTATUS1}}</view>
						<view v-else class="timebox">{{lang_info.PINSTATUS2}}</view>
					</block>
					
					<!--拼中模式下，是否拼中，是否退款，是否补偿，补偿内容-->
					<block v-if="detail.items[0].wanfa == 2">
						<block v-if="detail.is_team == 1">
							<view class="pingstyle pingstyle_success">{{lang_info.groups_order_result_pinzhong}}</view>
						</block>
						<block v-else-if="detail.is_team == 2">
							<view class="pingstyle pingstyle_fail">
								<text class="t1">{{lang_info.groups_order_result_not_pinzhong}}</text>
								<block v-if="detail.buchang_type == 1">
									<text class="t2">({{lang_info.groups_order_result_buchang_desc_coupon}})</text>
								</block>
								<block v-else-if="detail.buchang_type == 2">
									<text class="t2">({{lang_info.groups_order_result_buchang_desc_hongbao}}{{detail.hongbao}}-</text>
									<block v-if="detail.buchang_time == -1">
										<text class="t3">{{lang_info.groups_order_result_buchang_hongbao_1}}</text>
									</block>
									<block v-else-if="detail.buchang_time > 0">
										<text class="t4">{{lang_info.groups_order_result_buchang_hongbao_2}}</text>
									</block>
									<block v-else>
										<text class="t5">{{lang_info.groups_order_result_buchang_hongbao_3}}</text>
									</block>
									<text class="t2">)</text>
								</block>
							</view>
						</block>
					</block>
					
			        <!-- 商品列表 -->
			        <view class="goods bg-white">
			            <block v-if="detail.items.length > 0">
							<view :class="oneclass" v-for="(item, index) in detail.items" :key="index">
								<view class="goods-item oh">
									<navigator :url="'/pages/fcc/groups/detail/detail?goods_id=' + item.goods_id" hover-class="none">
										<image class="goods-image fl" :src="item.images" mode="aspectFill" />
										<view class="goods-base">
											<view class="goods-title multi-text">{{ item.title }}</view>
											<block v-if="item.spec != null">
												<view class="goods-attribute cr-888" v-for="(spec, index2) in item.spec" :key="index2">{{ spec.type }}:{{ spec.value }}</view>
											</block>
										</view>
									</navigator>
								</view>
								
								<view class="order-describe">
									<view class="jindutext">
										<text class="fr">{{lang_info.list_price_before}} {{ currency_symbol }}{{ item.price }}</text>
										<text v-if="item.original_price > 0" class="">{{lang_info.list_price_old_price}} {{ currency_symbol }}{{ item.original_price }}</text>
									</view>
									<view class="jindutiao">
										<progress :percent="detail.now_jindu" stroke-width="10" border-radius="8" activeColor="#fec330" active />
									</view>

								    <view class="jindubtn" v-if="detail.shengyurenshu > 0">
								        <view class="jindubtn_cc jd02 jindu_big">
								            <view>
												<!-- #ifdef H5 -->
												<button class="dis-block" type="default" size="default" @tap="share_h5_event" hover-class="none">
													<text>{{lang_info.team_detail_share_user_text}}</text>
												</button>
												<!-- #endif -->
												<!-- #ifdef MP-ALIPAY -->
												<button class="dis-block" type="default" size="default" @tap="share_base_event" hover-class="none">
													<text>{{lang_info.team_detail_share_user_text}}</text>
												</button>
												<!-- #endif -->
												<!-- #ifdef MP-WEIXIN || MP-BAIDU || MP-QQ || MP-TOUTIAO || MP-KUAISHOU -->
												<button class="dis-block" type="default" size="default" open-type="share" hover-class="none">
													<text>{{lang_info.team_detail_share_user_text}}</text>
												</button>
												<!-- #endif -->
												<!-- #ifdef APP-PLUS -->
												<button class="dis-block" type="default" size="default" hover-class="none" @tap="popup_share_event">
													<text>{{lang_info.team_detail_share_user_text}}</text>
												</button>
												<!-- #endif -->
								            </view>
								        </view>
								    </view>
								</view>
							</view>
			            </block>
			            <view class="teaminfo bg-white spacing-mb">
			                <view v-if="detail.shengyurenshu == 0" class="ts">{{lang_info.team_detail_enough_people_text}}</view>
			                <view v-else class="ts">
			                    {{lang_info.team_detail_people_num_before}}
			                    <text>{{ detail.shengyurenshu }}</text>
			                    {{lang_info.team_detail_people_num_after}}
			                </view>
			            
			                <view class="box">
			                    <view class="boxuser" v-for="(item, index) in team_user_list" :key="index">
			                        <image :src="item.avatar" mode="aspectFill" />
			            
			                        <view v-if="item.is_head == 1" class="tuanzhang userflag">{{lang_info.team_detail_team_header_text}}</view>
			            
			                        <view v-else class="chengyuan userflag">{{lang_info.team_detail_team_others_text}}</view>
			                    </view>
			                </view>
			            </view>
			        </view>
			    </view>
			</view>

			<view class="spacing-nav-title">
			    <text class="line"></text>
			    <text class="text-wrapper">{{lang_info.team_detail_wanfa_title}}</text>
			</view>
			<view class="wanfa spacing">
			    <view class="wanfacc weui-flex bg-white">
			        <view class="weui-flex__item">
			            <view class="placeholder">
			                <text>1</text>
			                {{lang_info.team_detail_wanfa_1}}
			            </view>
			        </view>
			        <view class="weui-flex__item">
			            <view class="placeholder">
			                <text>2</text>
			                {{lang_info.team_detail_wanfa_2}}
			            </view>
			        </view>
			        <view class="weui-flex__item">
			            <view class="placeholder">
			                <text>3</text>
			                {{lang_info.team_detail_wanfa_3}}
			            </view>
			        </view>
			    </view>
			</view>
			
			<view class="spacing-nav-title">
			    <text class="line"></text>
			    <text class="text-wrapper">{{lang_info.team_detail_cantuan_title}}</text>
			</view>
			<view class="panel-item spacing-mt teamlist">
			    <view class="panel-content bg-white">
			        <block v-if="(detail.teamusers || null) != null && detail.teamusers.length > 0">
			            <view class="tuan_li" v-for="(item, index) in detail.teamusers" :key="index">
			                <image :src="item.avatar" mode="aspectFill" />
			
			                <view class="whois">
			                    <text class="t1">{{ item.username }}</text>
			                    <text class="t2" :decode="true"></text>
			                </view>
			
			                <view class="liright">
			                    <text class="tinfo" :decode="true">{{ item.timestr }}</text>
			                </view>
			            </view>
			        </block>
			        <block v-else>
			            <view v-if="detail.teamusers.length == 0" class="tuan_li tc none_jilu">{{lang_info.team_detail_cantuan_no_record}}</view>
			        </block>
			    </view>
			</view>
			
			<!-- 分享弹窗 -->
			<component-share-popup :diyTheme="diytheme" ref="share"></component-share-popup>
        </view>

        <view v-if="detail == null">
            <component-no-data :propStatus="data_list_loding_status"></component-no-data>
        </view>
    </view>
</template>

<script>
	const app = getApp();
import componentPopup from '@/components/popup/popup';
import componentQuickNav from "@/components/quick-nav/quick-nav";
import componentBadge from '@/components/badge/badge';
import componentNoData from "@/components/no-data/no-data";
import componentBottomLine from "@/components/bottom-line/bottom-line";
import componentOnlineService from "@/components/online-service/online-service";
import componentFooter from "@/pages/fcc/groups/public/footer";
import componentCountdown from "@/pages/fcc/groups/public/countdown";
import componentSharePopup from "@/components/share-popup/share-popup";
import { groups_base_info, clear_user_cach } from '@/pages/fcc/groups/public/common.js';
var groups_static_url = app.globalData.get_static_url('groups', true);
var common_static_url = app.globalData.get_static_url('common');
export default {
	components: {
	    componentPopup,
		componentFooter,
		componentNoData,
		componentBottomLine,
		componentOnlineService,
		componentBadge,
		componentQuickNav,
		componentCountdown,
		componentSharePopup
	},
    data() {
        return {
			currency_symbol: app.globalData.currency_symbol(),
			currency_symbol_after: app.globalData.currency_symbol(),
            params: null,
			groups_static_url:groups_static_url,
			common_static_url:common_static_url,
            data_list_loding_status: 1,
            data_list_loding_msg: '',
            data_bottom_line_status: false,
            detail: null,
            detail_list: [],
            extension_data: [],
            site_fictitious: null,
            team_user_list: [],

            time: {
                status: 0,
                hours: '',
                minutes: '',
                seconds: ''
            },
			share_info:{},
            code: '',
            images: '',
            shengyurenshu: 0,
			oneclass:'br-b-dashed oh',
			// 多语言
			lang_info:{},
			diytheme: null
        };
    },
    onLoad(params) {
        //params['id'] = 19;
        this.setData({
            params: params
        });
        this.init();
    },
    onShow() {
		this.init_config();
		
        uni.setNavigationBarTitle({
            title: ''
        });
    },
    // 下拉刷新
    onPullDownRefresh() {
        this.init();
    },
    // 自定义分享
    onShareAppMessage() {
        var teamid = this.detail.teamid;
        return {
            title: this.detail.items[0].title + this.lang_info.team_detail_share_title_after,
            desc: app.globalData.data.application_describe,
            path: '/pages/fcc/groups/detail/detail?goods_id=' + this.detail.items[0].goods_id + '&teamid=' + teamid + '&ispin=1'
        };
    },
    methods: {
		// 初始化配置
		init_config(status) {
		    if ((status || false) == true) {
				this.setData({
				    currency_symbol: app.globalData.get_config('currency_symbol'),
				    common_app_is_online_service: app.globalData.get_config('config.common_app_is_online_service'),
				});
		    } else {
		        app.globalData.is_config(this, 'init_config');
		    }
		},
		
        // 获取数据列表
        init() {
        	// 先获取语言基础信息
        	groups_base_info()
        	.then(data=>{
        		this.init_before(data)
        		.then(()=>{
        			this.init_real();
        		});
        	});
        },
        
        // 设置本页参数
        init_before(data){
        	var self = this;
        	return new Promise((resolve, reject) => {
        		self.setData({
        			lang_info:data,
        		});
				uni.setNavigationBarTitle({
				    title: data.team_list_page_title
				});
        		resolve();
        	});
        },
        
        // 真正的数据初始化
        init_real(){
            var self = this;
            uni.showLoading({
                title: this.lang_info.loading_tips
            });
            this.setData({
                data_list_loding_status: 1
            });
            uni.request({
                url: app.globalData.get_request_url('orderdetail', 'index', 'groups'),
                method: 'POST',
                data: {
                    id: this.params.id
                },
                dataType: 'json',
                success: (res) => {
                    uni.hideLoading();
                    uni.stopPullDownRefresh();
                    console.log(res);

                    if (res.data.code == 0) {
                        var data = res.data.data;
						var oneclass = (data.data.items[0].shengyurenshu == 0) ? 'oh' : 'br-b-dashed oh';
                        self.setData({
							oneclass:oneclass,
                            detail: data.data,
                            team_user_list: data.data.teamusers,
							share_info:{
								'title':data.data.items[0].title + this.lang_info.team_detail_share_title_after,
								'img':data.data.items[0].images,
								'path':'/pages/fcc/groups/detail/detail',
								'query':'goods_id=' + data.data.items[0].goods_id + '&teamid=' + data.data.teamid + '&ispin=1'
							},
                            extension_data: data.data.extension_data || [],
                            site_fictitious: data.site_fictitious || null,
                            data_list_loding_status: 3,
                            data_bottom_line_status: true,
                            data_list_loding_msg: ''
                        });
                    } else {
                        self.setData({
                            data_list_loding_status: 2,
                            data_bottom_line_status: false,
                            data_list_loding_msg: res.data.msg
                        });

                        if (app.globalData.is_login_check(res.data, self, 'init')) {
                            app.globalData.showToast(res.data.msg);
                        }
                    }
					
					// 分享菜单处理
					app.globalData.page_share_handle(this.share_info);
                },
                fail: () => {
                    uni.hideLoading();
                    uni.stopPullDownRefresh();
                    self.setData({
                        data_list_loding_status: 2,
                        data_bottom_line_status: false,
                        data_list_loding_msg: self.lang_info.request_data_error_tips
                    });
                    app.globalData.showToast(self.lang_info.request_data_error_tips);
                }
            });
        },
	
		// 分享开启弹层
		popup_share_event(e) {
			if ((this.$refs.share || null) != null) {
				this.$refs.share.init({
					status: true,
					share_info: this.share_info
				});
			}
		},

        // h5分享
		share_h5_event() {
			//http://localhost:8082/#/pages/fcc/groups/teamdetail/teamdetail?id=12
			var str = app.globalData.get_page_url(false);//不要问号后面的
			str = str.replace('teamdetail/teamdetail','detail/detail');
			str += '?goods_id=' + this.detail.items[0].goods_id + '&teamid=' + this.detail.teamid + '&ispin=1';
		    app.globalData.text_copy_event(str);
		},
		
		// 基础分享事件
		share_base_event() {
			var self = this;
		    uni.pageScrollTo({
		        scrollTop: 0,
		        duration: 300,
		        complete: res => {
		            setTimeout(function() {
		                uni.showShareMenu({
							path:'/pages/fcc/groups/detail/detail?goods_id=' + self.detail.items[0].goods_id + '&teamid=' + self.detail.teamid + '&ispin=1'
						});
		            }, 500);
		        }
		    });
		}
    }
};
</script>
<style>
@import './teamdetail.css';
</style>
